home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / windows / capctrl.zip / SOURCE / CAPEDIT.PAS < prev   
Pascal/Delphi Source File  |  1997-03-21  |  7KB  |  251 lines

  1. unit CapEdit;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   CapCtrl, StdCtrls, ExtCtrls;
  8.  
  9. type
  10.   TCaptionButtonsEditor = class(TForm)
  11.     ItemsGroup: TGroupBox;
  12.     ItemPropGroup: TGroupBox;
  13.     ItemsListBox: TListBox;
  14.     NewBtn: TButton;
  15.     DeleteBtn: TButton;
  16.     CaptionLbl: TLabel;
  17.     CaptionEdit: TEdit;
  18.     EnabledBox: TCheckBox;
  19.     VisibleBox: TCheckBox;
  20.     PushedBox: TCheckBox;
  21.     OKBtn: TButton;
  22.     CancelBtn: TButton;
  23.     ApplyBtn: TButton;
  24.     KindLbl: TLabel;
  25.     KindCombo: TComboBox;
  26.     MyCaption: TCaptionControl;
  27.     procedure FormCreate(Sender: TObject);
  28.     procedure FormDestroy(Sender: TObject);
  29.     procedure CaptionEditChange(Sender: TObject);
  30.     procedure ItemsListBoxClick(Sender: TObject);
  31.     procedure DeleteBtnClick(Sender: TObject);
  32.     procedure ApplyBtnClick(Sender: TObject);
  33.     procedure NewBtnClick(Sender: TObject);
  34.     procedure MyCaptionButtonClick(Sender: TObject; ButtonIndex: Integer;
  35.       var Pushed: Boolean);
  36.   private
  37.     { Private declarations }
  38.     BtnList: TCaptionButtonsList;
  39.     CapCtrl: TCaptionControl;
  40.   public
  41.     { Public declarations }
  42.     procedure ReadBtnList(InBtn: TCaptionButtonsList);
  43.     procedure UpdateBtnList(OutBtn: TCaptionButtonsList);
  44.     procedure FillListBox;
  45.     procedure SelectFirstItem;
  46.   end;
  47.  
  48. function EditCaptionButtons(Buttons: TCaptionButtonsList; CaptionControl: TCaptionControl): Boolean;
  49.  
  50. implementation
  51.  
  52. {$R *.DFM}
  53.  
  54. uses
  55.   CapAbout;
  56.  
  57. function EditCaptionButtons(Buttons: TCaptionButtonsList; CaptionControl: TCaptionControl): Boolean;
  58. var
  59.   EditorForm: TCaptionButtonsEditor;
  60. begin
  61.   Result := False;
  62.   Application.CreateForm(TCaptionButtonsEditor, EditorForm);
  63.   with EditorForm do
  64.   try
  65.     CapCtrl := CaptionControl;
  66.     ReadBtnList(Buttons);
  67.     SelectFirstItem;
  68.     if ShowModal=mrOk then
  69.     begin
  70.       UpdateBtnList(Buttons);
  71.       Result := True;
  72.     end;
  73.   finally
  74.     Free;
  75.   end;
  76. end;
  77.  
  78. procedure TCaptionButtonsEditor.FormCreate(Sender: TObject);
  79. begin
  80.   BtnList := TCaptionButtonsList.Create(Self);
  81. end;
  82.  
  83. procedure TCaptionButtonsEditor.FormDestroy(Sender: TObject);
  84. begin
  85.   BtnList.Free;
  86. end;
  87.  
  88. procedure TCaptionButtonsEditor.ReadBtnList(InBtn: TCaptionButtonsList);
  89. var
  90.   i: Integer;
  91. begin
  92.   BtnList.Clear;
  93.   if InBtn.Count>0 then
  94.     for i:=0 to InBtn.Count-1 do
  95.       with InBtn[i] do
  96.         BtnList.AddButton(Caption, Enabled, Visible, Pushed, Kind);
  97.   FillListBox;
  98. end;
  99.  
  100. procedure TCaptionButtonsEditor.UpdateBtnList(OutBtn: TCaptionButtonsList);
  101. var
  102.   i: Integer;
  103. begin
  104.   while OutBtn.Count<BtnList.Count do
  105.     OutBtn.AddButton('x', True, True, False, cbkCustom);
  106.   while OutBtn.Count>BtnList.Count do
  107.     OutBtn.Delete(OutBtn.Count-1);
  108.   if BtnList.Count>0 then
  109.     for i:=0 to OutBtn.Count-1 do
  110.     begin
  111.       with OutBtn[i] do
  112.       begin
  113.         Enabled := BtnList[i].Enabled;
  114.         Visible := BtnList[i].Visible;
  115.         Pushed := BtnList[i].Pushed;
  116.         Caption := BtnList[i].Caption;
  117.         Kind := BtnList[i].Kind;
  118.       end;
  119.     end;
  120. end;
  121.  
  122. procedure TCaptionButtonsEditor.CaptionEditChange(Sender: TObject);
  123. var
  124.   b: Boolean;
  125. begin
  126.   b := CaptionEdit.Text <> '';
  127.   EnabledBox.Enabled := b;
  128.   VisibleBox.Enabled := b;
  129.   PushedBox.Enabled := b;
  130.   ApplyBtn.Enabled := b;
  131. end;
  132.  
  133. procedure TCaptionButtonsEditor.ItemsListBoxClick(Sender: TObject);
  134. var
  135.   b: Boolean;
  136.   i: Integer;
  137. begin
  138.   i:= ItemsListBox.ItemIndex;
  139.   b := ((i>=0) and (ItemsListBox.Items.Count>0));
  140.   DeleteBtn.Enabled := b;
  141.   CaptionEdit.Enabled := b;
  142.   EnabledBox.Enabled := b;
  143.   VisibleBox.Enabled := b;
  144.   PushedBox.Enabled := b;
  145.   ApplyBtn.Enabled := b;
  146.   if b then
  147.   begin
  148.     CaptionEdit.Text := BtnList[i].Caption;
  149.     EnabledBox.Checked := BtnList[i].Enabled;
  150.     VisibleBox.Checked := BtnList[i].Visible;
  151.     PushedBox.Checked := BtnList[i].Pushed;
  152.     KindCombo.ItemIndex := KindCombo.Items.IndexOf(BtnList[i].GetBtnKindStr);
  153.   end else
  154.   begin
  155.     CaptionEdit.Text := '';
  156.     EnabledBox.Checked := False;
  157.     VisibleBox.Checked := False;
  158.     PushedBox.Checked := False;
  159.     KindCombo.ItemIndex := KindCombo.Items.IndexOf('cbkCustom');
  160.   end;
  161. end;
  162.  
  163. procedure TCaptionButtonsEditor.DeleteBtnClick(Sender: TObject);
  164. var
  165.   i: Integer;
  166. begin
  167.   i := ItemsListBox.ItemIndex;
  168.   if i<0 then exit;
  169.   BtnList.Delete(i);
  170.   ItemsListBox.Items.Delete(i);
  171.   while i>=ItemsListBox.Items.Count do Dec(i);
  172.   if i>=0 then
  173.   begin
  174.     ItemsListBox.ItemIndex := i;
  175.     ItemsListBox.SetFocus;
  176.     ItemsListBoxClick(Self);
  177.   end;
  178.   ActiveControl := ItemsListBox;
  179. end;
  180.  
  181. procedure TCaptionButtonsEditor.FillListBox;
  182. var
  183.   i: Integer;
  184. begin
  185.   while ItemsListBox.Items.Count>BtnList.Count do
  186.     ItemsListBox.Items.Delete(ItemsListBox.Items.Count-1);
  187.   while ItemsListBox.Items.Count<BtnList.Count do
  188.     ItemsListBox.Items.Add('');
  189.   if BtnList.Count>0 then
  190.     for i:=0 to BtnList.Count-1 do
  191.       ItemsListBox.Items[i] := BtnList[i].Caption;
  192.   SelectFirstItem;
  193. end;
  194.  
  195. procedure TCaptionButtonsEditor.ApplyBtnClick(Sender: TObject);
  196. var
  197.   i: Integer;
  198. begin
  199.   i:=ItemsListBox.ItemIndex;
  200.   if i<0 then exit;
  201.   with BtnList[i] do
  202.   begin
  203.     Caption := CaptionEdit.Text;
  204.     Enabled := EnabledBox.Checked;
  205.     Visible := VisibleBox.Checked;
  206.     Pushed := PushedBox.Checked;
  207.     SetBtnKindStr(KindCombo.Items[KindCombo.ItemIndex]);
  208.     ItemsListBox.Items[i] := Caption;
  209.     ItemsListBox.SetFocus;
  210.     ItemsListBox.ItemIndex := i;
  211.     ItemsListBoxClick(Self);
  212.   end;
  213.   ActiveControl := ItemsListBox;
  214. end;
  215.  
  216. procedure TCaptionButtonsEditor.NewBtnClick(Sender: TObject);
  217. begin
  218.   BtnList.Add(TCaptionButton.Create);
  219.   with BtnList[BtnList.Count-1] do
  220.   begin
  221.     Caption := 'Untitled';
  222.     ItemsListBox.Items.Add(Caption);
  223.     ItemsListBox.ItemIndex := ItemsListBox.Items.Count-1;
  224.     ItemsListBoxClick(Self);
  225.   end;
  226.   ActiveControl := ItemsListBox;
  227. end;
  228.  
  229. procedure TCaptionButtonsEditor.SelectFirstItem;
  230. begin
  231.   if BtnList.Count=0 then exit;
  232.   ItemsListBox.ItemIndex := 0;
  233.   ItemsListBoxClick(Self);
  234.   ActiveControl := ItemsListBox;
  235. end;
  236.  
  237. procedure TCaptionButtonsEditor.MyCaptionButtonClick(Sender: TObject;
  238.   ButtonIndex: Integer; var Pushed: Boolean);
  239. var
  240.   AboutBox: TCaptionControlAbout;
  241. begin
  242.   Application.CreateForm(TCaptionControlAbout, AboutBox);
  243.   try
  244.     AboutBox.ShowModal;
  245.   finally
  246.     AboutBox.Free;
  247.   end;
  248. end;
  249.  
  250. end.
  251.